<?php
/**
 * Created by PhpStorm.
 * User: huang
 * Date: 2018/9/19 0019
 * Time: 13:51
 */

namespace app\api\model;

use app\common\model\PromotionFullMail as PromotionFullMailModel;

class PromotionFullMail extends PromotionFullMailModel
{
    /**
     * @var array
     */
    protected $hidden = ['create_time', 'modify_time', 'wxapp_id'];

    /**
     * 是否满足 满额包邮
     * @param $orderTotalPrice -订单总价
     * @param $address -收获地址
     * @return bool
     */
    public static function isFree($orderTotalPrice, $address)
    {
        $setting = self::detail();
        //未开启 满多少免邮费 活动
        if ($setting['is_open'] != 1) {
            return false;
        }
        //收货地址城市id
        $city_id = (string)$address['city_id'];

        //免邮费 不包含 的市id组
        $city_id_arr = explode(',', $setting['no_mail_city_ids']);
        if (!empty($city_id_arr) && in_array($city_id, $city_id_arr)) {
            return false;
        }

        $orderTotalPrice = round($orderTotalPrice, 2);
        $full_mail_money = round($setting['full_mail_money'],2);
        if ($orderTotalPrice >= $full_mail_money) {
            return true;
        } else {
            return false;
        }
    }
}